<!--suppress ALL -->
<include file="./Template/header.html" />
<link rel="stylesheet" type="text/css" href="/Template/css/hospitalOrderList.css?v=2021070904">
<script type="text/javascript">

    $(function() {

        //初始化页面配置
        initPage("订单列表");

        var app = new Vue({
            el: '#container',
            data: {
                orderList: [],
            },
            methods: {
                checkRole: function(employeeRoleId, roleId) {
                    var employeeRoleArr = employeeRoleId.split(",");
                    var roleArr = roleId.split(",");

                    var result = false;
                    $.each(roleArr, function(i,val){
                        if($.inArray(val, employeeRoleArr) != -1 || $.inArray((parseInt(val)+100).toString(), employeeRoleArr) != -1){
                            result = true;
                        }
                    });
                    return result;
                },
                approve: function(orderId) {
                    window.location.href = "/wechat/hospitalProduct/hospitalOrder/id/" + orderId;
                },
                getReportList: function(reportList) {
                    var reportListArr = reportList.split(",");
                    return reportListArr;
                },

                getOrderDetailList: function(productList, numberList) {

                    var productListArr = productList.split(",");
                    var numberListArr = numberList.split(",");
                    var detailArr = new Array(productListArr.length);
                    var allProductListArr=<?php echo json_encode($allProductList);?>;
                    var allProductList=eval(allProductListArr);

                    for (var i = 0; i < productListArr.length; i++) {
//                        alert(productListArr[i]);
                        for (var j = 0; j < allProductListArr.length; j++) {
                            if(productListArr[i] == allProductList[j]["hospital_product_id"]){
//                                alert(allProductList[j]["hospital_product_name"]);
                                detailArr[i] = new Array(3)
                                detailArr[i]["hospital_product_name"] = allProductList[j]["hospital_product_name"];
                                detailArr[i]["code"] = allProductList[j]["code"];
                                detailArr[i]["number"] = numberListArr[i];
//                                break;
                            }
                        }
                    }
                    return detailArr;
                },
                showNameCode: function() {
                    var text = $("#showNameCode").html();
                    if(text == "显示编码"){
                        $(".product_name").hide();
                        $(".product_code").show();
                        $("#showNameCode").html("显示名称");
                    }
                    if(text == "显示名称"){
                        $(".product_name").show();
                        $(".product_code").hide();
                        $("#showNameCode").html("显示编码");
                    }
                },
            }
        })

        function getOrderList(status, ignoreOrderId) {

            $.ajax({
                url:"/wechat/hospitalProduct/getOrderList",
                type:"post",
                data:{
                    status: status,
                    orderId: '{$orderId}',
                    ignoreOrderId: ignoreOrderId
                },
                dataType:"JSON",
                beforeSend:function(){
                    $("#loadingToast").show();
                },
                complete:function(){
                    $('#loadingToast').hide();
                },
                success:function(data){
                    app.orderList = data;
                    setTimeout(function() {
                        $(".ui-item.measure-info img").bind("click", function() {
                            var upUrl = "/Template/images/icon-up.png";
                            var downUrl = "/Template/images/icon-down.png";
                            $(this).parent().next().toggle();
                            if($(this).attr("src") == upUrl) {
                                $(this).attr("src", downUrl);
                            } else {
                                $(this).attr("src", upUrl);
                            }
                        });
                        $(".ui-item.measure-info img").each(function() {
                            $(this).trigger("click");
                        });
                    },200);
                },
            })
        }

        $("#my-order ul li").bind("click", function() {

            if($(this).hasClass("active")) {
                return false;
            }

            var status = $(this).attr("data-status");

            $("#my-order ul li").each(function() {
                $(this).removeClass("active");
            });

            $(this).addClass("active");

            getOrderList(status, 1);

        });


        if(isNullOrEmpty("{$orderId}")){
            getOrderList(0);
        }else{
            getOrderList();
            $(".li-status-2").removeClass("active");
            $(".li-status-1").removeClass("active");
            $(".li-status1").removeClass("active");
            $(".li-status0").removeClass("active");
            switch('{$orderStatus}'){
                case '-2':
                    $(".li-status-2").attr("class","active");
                    break;
                case '-1':
                    $(".li-status-1").attr("class","active");
                    break;
                case '1':
                    $(".li-status1").attr("class","active");
                    break;
                case '0':
                    $(".li-status0").attr("class","active");
                    break;
            }
        }

//        if (window.history && window.history.pushState) {
//            $(window).on('popstate', function () {
//                window.history.pushState('forward', null, '#');
//                window.history.forward(1);
//            });
//        }
//        window.history.pushState('forward', null, '#'); //在IE中必须得有这两行
//        window.history.forward(1);


    });


</script>
<div class="container" id="container">
    <div id="my-order">
        <ul>
            <li class="li-status-2" data-status="-2">
                <span>未提交</span>
            </li>
            <li class="li-status-1" data-status="-1">
                <span>待处理</span>
            </li>
            <li class="li-status1" data-status="1">
                <span>已出库</span>
            </li>
            <li class="li-status0 active" data-status="0">
                <span>全部</span>
            </li>
        </ul>
    </div>
    <div class="order-detail">
        <div class="no-data" v-if="orderList == null">暂无数据</div>
        <button class="name-code-button" id="showNameCode" v-on:click="showNameCode()">显示编码</button>
        <div class="order-info" v-for="order in orderList">
            <div class="status active" v-if="order.status == -1">
                <img src="/Template/images/icon-waiting.png" alt="">
                <span class="status-content">{{order.admin_name}} (待处理)</span>
            </div>
            <div class="status active" v-if="order.status == 1">
                <img src="/Template/images/icon-clock.png" alt="">
                <span class="status-content">{{order.admin_name}} (已出库)</span>
            </div>
            <div class="status active" v-if="order.status == -3">
                <img src="/Template/images/icon-clock.png" alt="">
                <span class="status-content">{{order.admin_name}} (已关闭)</span>
            </div>
            <div class="status active" v-if="order.status == -2">
                <img src="/Template/images/icon-approval.png" alt="">
                <span class="status-content">{{order.admin_name}} (未提交)</span>
            </div>
            <div class="have-padding">
                <div class="product-info">
                    <!--<img class="product-img" src="{{order.image_url}}" alt="product">-->
                    <div class="detail-info">
                        <p class="product-price" style="color: #3fcca9;font-weight: bold">【{{order.hospital_name}}】</p>
                        <p class="product-name" style="color: #7171cc;font-weight: bold;">{{order.hospital_operation_name}}</p>
                        <p class="update_time">更新时间：{{order.update_time}}</p>
                        <p class="number">共计：<a style="color: #e97a15; font-weight: bold;">{{order.number}}</a> 件</p>
                    </div>
                </div>
                <div class="line"></div>
                <div class="user-order-info">
                    <div class="ui-item pickUp-info">
                        <span class="item-left">单号</span>
                        <span class="item-right">{{order.hospital_order_no}}</span>
                    </div>
                    <div class="ui-item pickUp-info">
                        <span class="item-left">下单日期</span>
                        <span class="item-right">{{order.create_date}}</span>
                    </div>
                    <div class="ui-item pickUp-info">
                        <span class="item-left">手术日期</span>
                        <span class="item-right" style="color: #e97a15">{{order.op_date}}</span>
                    </div>
                    <div class="ui-item pickUp-info">
                        <span class="item-left">手术医生</span>
                        <span class="item-right">{{order.doctor_name}}</span>
                    </div>
                    <div class="ui-item pickUp-info">
                        <span class="item-left">病人姓名</span>
                        <span class="item-right">{{order.patient_name}}</span>
                    </div>
                    <div class="ui-item messege-left">
                        <span class="item-left">留言备注</span>
                        <span class="item-right" style="color: #e97a15">{{order.note == "" ? "暂无":order.note}}</span>
                    </div>
                    <div v-if="order.status > 0">
                        <div class="ui-item pickUp-info">
                            <span class="item-left">出库</span>
                            <span class="item-right"><a style="color: #7171cc;">{{order.outstock_time}}</a> {{order.delivery_name}}</span>
                        </div>
                    </div>
                    <!--div class="ui-item pickUp-info">
                        <span class="item-left">
                            <button class="view-button" v-on:click="approve(order.hospital_order_id)">查 看</button>
                        </span>
                        <span class="item-right">
                            <button class="approve-button" style="background-color: #1dccaa;" v-on:click="approve(order.hospital_order_id)" v-if="order.status == '-1' && checkRole('{$user.role}', '1')">出 库</button>
                            <button class="approve-button" style="background-color: #ff7976;" v-on:click="approve(order.hospital_order_id)" v-if="order.status == -1 && order.employee_id == '{$user.employee_id}'">修 改</button>
                            <button class="approve-button" v-on:click="approve(order.hospital_order_id)" v-if="order.status == -2 && order.employee_id == '{$user.employee_id}'">提 交</button>
                        </span>
                    </div-->


                </div>
                <div class="finishedProduct-detail-info">
                    <div class="ui-item measure-info">
                        <span class="item-class">
                            <button class="approve-button" style="background-color: #1dccaa;" v-on:click="approve(order.hospital_order_id)" v-if="order.status == '-1' && checkRole('{$user.role}', '1,13')">出 库</button>
                            <!--<button class="approve-button" style="background-color: #ff7976;" v-on:click="approve(order.hospital_order_id)" v-if="order.status == -1 && order.employee_id == '{$user.employee_id}'">修 改</button>-->
                            <button class="approve-button" v-on:click="approve(order.hospital_order_id)" v-if="order.status == -2 && order.employee_id == '{$user.employee_id}'">提 交</button>
                            &nbsp;
                        </span>
                        <span class="item-detailname">订单详情</span>
                        <img class="icon-up" src="/Template/images/icon-up.png" alt="">
                    </div>
                    <div>
                        <div class="ui-item fast-post" v-for="(index,keyword) in getOrderDetailList(order.product_list, order.number_list)">
                            <span class="item-left" style="color: #7171cc;width: 7%;text-align: right;font-weight: normal;font-size: 0.8rem">({{index+1}})</span>
                            <span class="item-right" style="color: #7171cc;width: 7%;text-align: right;font-weight: normal; float: right;font-size: 0.8rem;">x {{keyword.number}}</span>
                            <span class="item-center product_name" style="color: #7171cc;width: 81%;font-weight: normal; float: right;">{{keyword.hospital_product_name}}</span>
                            <span class="item-center product_code" style="color: #7171cc;width: 81%;font-weight: normal;display: none">{{keyword.code}}</span>
                            </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<include file="./Template/footer.html" />

